package servlet_teacher;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Student;
import factory.DaoFactory;

/**
 * Servlet implementation class TeacherAddStudentServlet
 */
@WebServlet("/servlet_addstudent_teacher")
public class TeacherAddStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public TeacherAddStudentServlet() {
		super();

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		/* studentnumber,studentname,examname,classroom */
		HttpSession session = request.getSession();
		String studentnumber = request.getParameter("addstudentnumber");
		String studentname = request.getParameter("addstudentname");
		String classroom = request.getParameter("addclassroom");
		String examname = session.getAttribute("examname").toString();
		System.out.println("servlet:"+studentname+studentnumber+examname+classroom);
		Student student = new Student();
		student.setClassroom(classroom);
		student.setExamname(examname);
		student.setStudentname(studentname);
		student.setStudentnumber(studentnumber);
		DaoFactory.getTeacherDaoInstance().addstudent(student);
		
		response.sendRedirect("jsp/teacher/teacher_manage_student.jsp");
		            
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
